package com.ruoyi.bearing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bearing.domain.ComponentLabels;
import com.ruoyi.bearing.service.IComponentLabelsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 元器件型号管理Controller
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/bearing/label")
public class ComponentLabelsController extends BaseController
{
    @Autowired
    private IComponentLabelsService componentLabelsService;

    /**
     * 查询元器件型号管理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComponentLabels componentLabels)
    {
        startPage();
        List<ComponentLabels> list = componentLabelsService.selectComponentLabelsList(componentLabels);
        return getDataTable(list);
    }

    /**
     * 导出元器件型号管理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:label:export')")
    @Log(title = "元器件型号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComponentLabels componentLabels)
    {
        List<ComponentLabels> list = componentLabelsService.selectComponentLabelsList(componentLabels);
        ExcelUtil<ComponentLabels> util = new ExcelUtil<ComponentLabels>(ComponentLabels.class);
        util.exportExcel(response, list, "元器件型号管理数据");
    }

    /**
     * 获取元器件型号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bearing:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId)
    {
        return success(componentLabelsService.selectComponentLabelsByLabelId(labelId));
    }

    /**
     * 新增元器件型号管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:label:add')")
    @Log(title = "元器件型号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComponentLabels componentLabels)
    {
        return toAjax(componentLabelsService.insertComponentLabels(componentLabels));
    }

    /**
     * 修改元器件型号管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:label:edit')")
    @Log(title = "元器件型号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComponentLabels componentLabels)
    {
        return toAjax(componentLabelsService.updateComponentLabels(componentLabels));
    }

    /**
     * 删除元器件型号管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:label:remove')")
    @Log(title = "元器件型号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds)
    {
        return toAjax(componentLabelsService.deleteComponentLabelsByLabelIds(labelIds));
    }
}
